/**
 * @file categories/binary_tree/reconstruct_preorder/main.cpp
 * @brief
 * @see https://www.luogu.com.cn/problem/P1827
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/8 10:18:02
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 10;
int n;
char inorder[N], postorder[N];
void reconstruct(int inLeft, int inRight, int postLeft, int postRight) {
  if (inLeft < inRight && postLeft < postRight) {
    int root = postorder[postRight - 1];
    putchar(root);
    int k = find(inorder, inorder + n, root) - (inorder + inLeft);
    reconstruct(inLeft, inLeft + k, postLeft, postLeft + k);
    reconstruct(inLeft + k + 1, inRight, postLeft + k, postRight - 1);
  }
}
int main() {
  // High rating and good luck!
  cin >> inorder >> postorder;
  n = strlen(postorder);
  reconstruct(0, n, 0, n);
  return 0;
}
